<template>
  <!-- 仿央视新闻顶部导航栏 -->
  <view class="news-header">
    <text class="header-title">新闻</text>
  </view>

  <!-- 新闻列表容器 -->
  <view class="news-container">
    <!-- 置顶新闻区域（单独展示，突出置顶） -->
    <view v-if="hasTopNews" class="top-news-wrapper">
      <view class="top-label">置顶</view>
      <NewsView 
        :title="topNews.title"
        :isTop="topNews.isTop"
        :author="topNews.author"
        :comments="topNews.comments"
        :time="topNews.time"
        :tags="topNews.tags"
        :imgUrl="topNews.imgUrl"
      />
    </view>

    <!-- 普通新闻列表 -->
    <NewsView
      v-for="(item, index) in normalNewsList" 
      :key="`news-${index}-${item.title}`"
      :title="item.title"
      :isTop="item.isTop"
      :author="item.author"
      :comments="item.comments"
      :time="item.time"
      :tags="item.tags"
      :imgUrl="item.imgUrl"
    />
  </view>
</template>

<script>
// 【关键修复】确保路径是 components11
import NewsView from '../../components11/newsview.vue';
// 导入本地新闻数据
import newsData from '../../Data/news.json';

export default {
  name: 'Newspage',
  components: { NewsView },
  data() {
    return {
      newsList: []
    };
  },
  mounted() {
    // 确保数据加载
    this.loadNews();
  },
  computed: {
    hasTopNews() {
      return this.newsList && this.newsList.some(item => item.isTop);
    },
    topNews() {
      return this.newsList.find(item => item.isTop) || {};
    },
    normalNewsList() {
      return this.newsList.filter(item => !item.isTop) || [];
    }
  },
  methods: {
    loadNews() {
      // 容错：防止数据为空
      this.newsList = newsData || [];
    }
  }
};
</script>

<style scoped>
/* 仿央视新闻顶部导航 */
.news-header {
  background-color: #c91f37; /* 央视新闻红色主色调 */
  color: #fff;
  padding: 12px 16px;
  text-align: center;
}
.header-title {
  font-size: 20px;
  font-weight: bold;
  margin-right: 8px;
}
.header-subtitle {
  font-size: 14px;
  opacity: 0.9;
}

/* 新闻容器 */
.news-container {
  background-color: #f5f5f5;
  padding: 16px;
  min-height: calc(100vh - 56px); /* 减去导航栏高度 */
}

/* 置顶新闻包装器：突出展示 */
.top-news-wrapper {
  margin-bottom: 24px;
  border: 1px solid #c91f37;
  border-radius: 8px;
  overflow: hidden;
}
/* 置顶标签（单独放大） */
.top-label {
  background-color: #c91f37;
  color: #fff;
  font-size: 14px;
  padding: 4px 8px;
}
</style>